//
//  SDProductListVC.m
//  skinDetection
//
//  Created by  liangzhun on 2018/10/29.
//  Copyright © 2018年  liangzhun. All rights reserved.
//

#import "SDProductListVC.h"
#import "SDHomeHeaderView.h"
#import "SDProductListCell.h"
#import "SDProductDetailVC.h"
#import "SDHomeProductList.h"

static NSString *const cellIden = @"SDProductListCell";


@interface SDProductListVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)NSArray *listArray;
@end

@implementation SDProductListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navHeight.constant = SDNavBar_Height;
    [self.titleLab setText:self.coateTitle];
    [self.collectionView registerNib:[UINib nibWithNibName:cellIden bundle:nil] forCellWithReuseIdentifier:cellIden];
    [self loadData];
    
}
- (void)loadData
{
    [SDNetwork getProductCategoryListWithTypeId:self.type Finish:^(NSDictionary * _Nullable dic, NSError * _Nullable error) {
        if (!error) {
            self.listArray = dic[@"data"];
            [self.collectionView reloadData];
        }
    }];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.listArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SDProductListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIden forIndexPath:indexPath];
    cell.list = [SDHomeProductList modelObjectWithDictionary:self.listArray[indexPath.row]];
    return cell;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((SDMainScreenWidth - 45)/2.0, 78 + (SDMainScreenWidth - 45 - 60)/2.0);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(15, 15, 0, 15);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    SDProductDetailVC *vc = [SDMethodTool getViewControlWithIdentifier:NSStringFromClass([SDProductDetailVC class])];
    SDHomeProductList *list = [SDHomeProductList modelObjectWithDictionary:self.listArray[indexPath.row]];
    vc.list = list.bImg;
    [self.navigationController pushViewController:vc animated:YES];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)back:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
